package com.wans.easyuibackend.utils.validation;


import org.springframework.stereotype.Component;

import java.time.LocalDate;

@SuppressWarnings({"all"})
@Component
public class ContentValidation {

    /**
     * @param gender 性别
     * @return true正确  false错误
     */
    public boolean staffGenderVerify(Integer gender) {
        if (gender == null) {
            return false;
        }

        switch (gender) {
            case 0, 1:
                return true;
            default:
                return false;  //未能匹配
        }

    }


    /**
     * @param identityType 身份类型
     * @return true正确  false错误
     */
    public boolean staffIdentityTypeVerify(Integer identityType) {
        if (identityType == null) {
            return false;
        }

        switch (identityType) {
            case 1, 2, 3, 4, 5, 6:
                return true;
            default:
                return false;  //未能匹配
        }
    }

    /**
     * 各类证件校验
     *
     * @param identityType 证件类型
     * @param identity     证件号
     * @return 校验通过返回true，否则返回false
     */
    public boolean staffIdentityVerify(Integer identityType, String identity) {
        if (identityType == null) {
            return false;
        }
        if (identity == null) {
            return false;
        }

        switch (identityType) {
            case 1:
                return AContentValidation.isIDCard(identity);
            case 2:
                return AContentValidation.isofficerCard(identity);
            case 3:
                return false;  //学生证一般没有号码
            case 4:
                return AContentValidation.isDriveCard(identity);
            case 5:
                return AContentValidation.isPassPortCard(identity);
            case 6:
                return AContentValidation.isHMCard(identity);
            default:
                return false;  //未能匹配
        }
    }


    /**
     * 手机号校验
     *
     * @param phoneNumber 手机号
     * @return 校验通过返回true，否则返回false
     */
    public boolean staffPhoneNumberVerify(String phoneNumber) {
        return AContentValidation.isPhoneNumber(phoneNumber);
    }

    /**
     * 电子邮箱校验
     *
     * @param email 电子邮箱
     * @return 校验通过返回true，否则返回false
     */
    public boolean staffEmailVerify(String email) {
        return AContentValidation.isEmail(email);
    }


    /**
     * //校验身份证件上的出生日期与填写的是否一致
     *
     * @param identityType
     * @param identity
     * @param birthday
     * @return
     */
    public boolean staffIdentityDateVerify(Integer identityType, String identity, LocalDate birthday) {
        if (identityType != 1) {
            return true;
        }

        if (identity.length() == 18) {
            String identityDate = identity.substring(6, 14);
            String birthdayDate = birthday.toString().replaceAll("-", "");
            return identityDate.equals(birthdayDate);
        } else {
            String identityDate = "19" + identity.substring(6, 12);
            String birthdayDate = birthday.toString().replaceAll("-", "");
            return identityDate.equals(birthdayDate);
        }
    }
}
